package com.leetcode.week.week291;

import java.util.HashMap;
import java.util.Map;

/**
 * @author angzhijin
 * @Description
 * @create 2022-05-01 11:03 上午
 */
public class LeetCodeWeek2 {
    public static void main(String[] args) {

    }

    public int minimumCardPickup(int[] cards) {
        if(cards.length <2) return -1;
        int length = cards.length;
        int min = length+1;
        Map<Integer,Integer> hash = new HashMap<>();
        for (int i = 0; i < length; i++) {
            if (hash.containsKey(cards[i])){
                min = Math.min(min, i-hash.get(cards[i])+1);
            }
            hash.put(cards[i],i);
        }
        return min>length?-1:min;
    }
}
